<?php
/**
 * This file is form http://findcat.cn
 *
 * @link     https://findcat.cn
 * @email    1476982312@qq.com
 */
namespace App\Http\Controllers\Admin;

use App\Models\User;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use App\Models\UserOath;
use App\Traits\AdminHelp;
use Encore\Admin\Auth\Database\Administrator;
use Encore\Admin\Controllers\AdminController;

class UserOauthController extends AdminController
{
    use AdminHelp;

    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '第三方授权管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new UserOath());

        $grid->expandFilter();

        $grid->column('id', 'ID')->sortable();
        $grid->column('nickname', '昵称');
        $grid->column('email', '邮箱');
        $grid->column('avatar', '头像')->image('',50, 50);
        $grid->column('token', 'Token');
        $grid->column('provider', '来源');
        $grid->column('admin_user_id', '操作人')->display(function ($value) {
            return Administrator::query()->find($value)->name ?? '';
        });
        $grid->column('created_at', '创建时间');

        $grid->setActionClass(Grid\Displayers\Actions::class);

        $grid->filter(function (Grid\Filter $filter) {
            $filter->equal('nickname', '昵称');
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(UserOath::query()->findOrFail($id));

        $show->field('id', 'ID');
        $show->field('nickname', '昵称');
        $show->field('email', '邮箱');
        $show->field('avatar', '头像');
        $show->field('token', 'Token');
        $show->field('provider', '来源');
        $show->field('admin_user_id', '操作人');
        $show->field('created_at', '创建时间');
        $show->field('updated_at', '修改时间');

        return $show;
    }
}
